package com.zzyl.nursing.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.domain.QuerryPage;
import com.zzyl.nursing.mapper.MemberProjectMapper;
import com.zzyl.nursing.service.MemberProjectService;
import org.springframework.stereotype.Service;

import static com.github.pagehelper.page.PageMethod.startPage;


@Service
public class MemberProjectServiceImpl extends ServiceImpl<MemberProjectMapper, NursingProject> implements MemberProjectService {
    @Override
    public TableDataInfo<NursingProject> getPage(QuerryPage querryPage) {
        Page<NursingProject> page = new Page(querryPage.getPageNum(), querryPage.getPageSize());
        page.addOrder(OrderItem.desc("create_time"));
        //查询之前添加的条件select * from nursing_project where name like ? and status = ?
        Page<NursingProject> page1 = lambdaQuery()
                .like(querryPage.getName() != null && querryPage.getName() != "", NursingProject::getName, querryPage.getName())
                .eq(querryPage.getStatus() != null, NursingProject::getStatus, querryPage.getStatus())
                .page(page);
        TableDataInfo<NursingProject> nursingProjectTableDataInfo = new TableDataInfo<>(page1.getRecords(),(int)page1.getTotal());
        nursingProjectTableDataInfo.setCode(200);
        return nursingProjectTableDataInfo;
    }

    @Override
    public NursingProject getDetail(Long id) {
        NursingProject one = lambdaQuery().eq(NursingProject::getId, id).one();
        return one;
    }


}
